import request from '@/utils/request'
import { parseStrEmpty } from "@/utils/ruoyi";

// 查询用户列表
export function listUser(query) {
  return request({
    url: '/system/user/list',
    method: 'get',
    params: query
  })
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/system/user/details/' + parseStrEmpty(userId),
    method: 'get'
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/system/user/save',
    method: 'post',
    data: data
  })
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/system/user/edit',
    method: 'put',
    data: data
  })
}

// 删除用户
export function delUser(userId) {
  return request({
    url: '/system/user/delete/' + userId,
    method: 'delete'
  })
}

// 用户密码重置
export function resetUserPwd(userId, password) {
  const query = { password }
  return request({
    url: '/system/user/reset/password/' + userId,
    method: 'get',
    params: query
  })
}

// 用户密码重置
export function updateUserPwd(oldPass, newPass) {
  const query = {
    oldPass,
    newPass
  }
  return request({
    url: '/system/user/edit/password',
    method: 'get',
    params: query
  })
}

// 修改用户头像
export function updateAvatar(data) {
  return request({
    url: '/system/user/edit/avatar',
    method: 'put',
    data: data
  })
}

// 用户文件上传
export function uploadFile(query, data) {
  return request({
    url: '/file/file/upload',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: query,
    data: data
  })
}